<template>
  <div class="content">
    <div class="box">
      <!-- 原密码 -->
      <van-field v-model="password1" type="password" maxlength="16" clearable placeholder="请输入当前密码" />
      <van-field v-model="password2" type="password" maxlength="16" clearable placeholder="请输入新的密码" />
      <van-field v-model="password3" type="password" maxlength="16" clearable placeholder="再次输入新的密码" />
    </div>
    <div class="footer">
      <van-button type="info" @click="changePassword">确定</van-button>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      password1: "",
      password2: "",
      password3: "",
    };
  },
  methods: {
    changePassword() {
      // 先做非空验证
      if (this.password1 == "") {
        this.$toast.fail("请输入当前密码");
      } else if (this.password2 == "") {
        this.$toast.fail("请输入新密码");
      } else if (this.password3 == "") {
        this.$toast.fail("请输入确认密码");
      } else if (this.password2 != this.password3) {
        this.$toast.fail("两次输入密码不一致");
      } else {
        (async () => {
          const data = await this.get("/user/resetPassword", {
            yuanPassword: this.password1,
            xianPassword: this.password3,
            userId: localStorage.getItem("id")
          });
          console.log(data);
          if (data.code == 200) {
            this.$toast.success(data.msg);
            this.$router.back();
          } else {
            this.$toast.fail(data.msg);
          }
        })();
      }
    },
  },
};
</script>

<style lang="scss" scoped>
.content {
  font-size: 0.1rem;
  width: 100%;
  height: 100%;
  background-color: #f7f9fa;
  box-sizing: border-box;
  position: relative;
  .footer {
    position: absolute;
    left: 0;
    bottom: 0;
    width: 100%;
    .van-button {
      width: 100%;
    }
  }
}
</style>